package com.tebiecloud.mpopen.server.utils;

import com.tebiecloud.common.utils.NetworkUtils;

/**
 * 第三方应用接口接口，请参照 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=&lang=zh_CN
 * @author chenxiaoc
 *
 */
public class MPSuiteApi {

	private final static String PostApi_component_token = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
	private final static String PostComponent_access_token = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=%s";
	private final static String PostApi_query_auth = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s";
	private final static String PostApi_authorizer_token = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s";
	private final static String PostApi_get_authorizer_info = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s";
//	private final static String PostGet_corp_token = "https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token?suite_access_token=%s";
	// 网页授权
	private final static String GetAccess_token = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s&component_access_token=%s";
	
	/** 获取第三方平台component_access_token */
	public static String api_component_token(String data) {
		return NetworkUtils.doPost(PostApi_component_token, data);
	}
	
	/** 获取预授权码pre_auth_code */
	public static String component_access_token(String component_access_token, String data) {
		return NetworkUtils.doPost(String.format(PostComponent_access_token, component_access_token), data);
	}
	
	/** 使用授权码换取公众号的接口调用凭据和授权信息 */
	public static String api_query_auth(String component_access_token, String data) {
		return NetworkUtils.doPost(String.format(PostApi_query_auth, component_access_token), data);
	}
	
	/** 获取（刷新）授权公众号的接口调用凭据（令牌） */
	public static String api_authorizer_token(String component_access_token, String data) {
		return NetworkUtils.doPost(String.format(PostApi_authorizer_token, component_access_token), data);
	}
	
	/** 获取授权方的公众号帐号基本信息 */
	public static String api_get_authorizer_info(String component_access_token, String data) {
		return NetworkUtils.doPost(String.format(PostApi_get_authorizer_info, component_access_token), data);
	}
	
//	/** 获取企业号access_token */
//	public static String get_corp_token(String suite_access_token, String data) {
//		return NetworkUtils.doPost(String.format(PostGet_corp_token, suite_access_token), data);
//	}
	
	/** 网页授权 */
	public static String access_token(String appid, String code, String component_appid, String component_access_token) {
		return NetworkUtils.doGet(String.format(GetAccess_token, appid, code, component_appid, component_access_token));
	}
	
}
